package com.apinji.common.domain.mapper;

import com.apinji.common.domain.UserCardToken;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by 轩辕夏夏 on 2017/7/1.
 */
@Mapper
public interface UserCardTokenMapper {


    /**
     * 添加用户常用卡
     *
     * @param userCardToken
     * @return
     */
    @Insert("insert into apin_user_card_token(id, cardtype, cardno, cardlastno, expired, phoneno, tokenlevel, tokenbegin, tokenend, tokentype, token, trid, useruuid, createtime, bankshortname, bankfullname, bankname, iconurl) " +
            " values(#{id}, #{cardType}, #{cardNo}, #{cardLastNo}, #{expired}, #{phoneNo}, #{tokenLevel}, #{tokenBegin}, #{tokenEnd}, #{tokenType}, #{token}, #{trId}, #{userUUID}, #{createTime}, #{bankShortName}, #{bankFullName}, #{bankName}, #{iconUrl})")
    void addBankCardToken(UserCardToken userCardToken);


    /**
     * 查询用户常用的卡信息
     * @param userUUID
     * @return
     */
    @Select("select * from apin_user_card_token where useruuid = #{userUUID}")
    List<UserCardToken> getInUsedCards(@Param("userUUID") String userUUID);


    /**
     * 根据银行卡号，获取到唯一的 卡号token绑定信息
     * @param cardNo
     * @return
     */
    @Select("SELECT * FROM apin_user_card_token WHERE cardno = #{cardNo} AND useruuid = #{userUUID}")
    UserCardToken getOneByCardNo(@Param("userUUID") String userUUID, @Param("cardNo") String cardNo);

    @Select("select * from apin_user_card_token where id = #{id} and useruuid = #{userUUID}")
    UserCardToken getOneById(@Param("id") String id, @Param("userUUID") String userUUID);

    @Delete("delete from apin_user_card_token where id = #{id}  and useruuid = #{userUUID}")
    void delById(@Param("id") String id, @Param("userUUID") String userUUID);

}
